import pygame
from pygame.sprite import Sprite
import random

class Drop(Sprite):
    # 表示单个水滴的类
    def __init__(self,dg_settings,screen):
        # 初始化外星人并设置其起始位置
        super(Drop,self).__init__()
        self.screen = screen
        self.dg_settings = dg_settings
        # 加载雨滴图像，并设置其rect属性
        self.image = pygame.image.load('image/drop.png')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        # 将雨滴最初绘制在最上边的中间
        self.rect.centerx = random.randint(1,700)
        self.rect.top = self.screen_rect.top
        # 存储雨滴的准确位置
        self.x = self.rect.centerx

    def blitme(self):
        # 在指定位置绘制雨滴
        self.screen.blit(self.image,self.rect)

    def update(self):
            self.rect.y += self.dg_settings.drop_speed_factor
            self.rect.x = self.x